﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PostSubmit
{
    public partial class AutoLogin : Form
    {
        public AutoLogin()
        {
            InitializeComponent();
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            HtmlElement ClickBtn = null;
            string reslt = string.Empty;
            if (e.Url.ToString().ToLower().IndexOf("login.aspx", System.StringComparison.Ordinal) > 0)
            {
                HtmlDocument doc = webBrowser1.Document;
                for (int i = 0; i < doc.All.Count; i++)
                {
                    if (doc.All[i].TagName.ToUpper().Equals("INPUT"))
                    {
                        switch (doc.All[i].Name)
                        {
                            case "txtUsername":
                                doc.All[i].InnerText = "tcexception";　　// 用户名
                                break;
                            case "txtPassword":
                                doc.All[i].InnerText = "tc@%exception";　　　　　　// 密码
                                break;
                            case "ext-gen25":
                                ClickBtn = doc.All[i];
                                break;
                        }
                    }
                    reslt += string.Format("{0}-{1}\r\n", doc.All[i].TagName, doc.All[i].Name);
                }

                richTextBox1.Text = doc.GetElementById("txtUsername").InnerText;
                //ClickBtn.InvokeMember("Click");　　　　　　　　　　　　// 点击“登录”按钮
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sUrl = textBox1.Text.Trim();
            if (sUrl.Length > 0)
            {
                webBrowser1.Navigate(sUrl);
            }
        }
    }
}
